const express = require('express');
const app = express();
app.listen(3000,(req,res)=>{console.log('已开启服务器')})


const mysql = require('mysql')
const con = mysql.createConnection({
    host:'localhost',
    port:3306,
    user:'root',
    password:'root',
    database:'member',
})
con.connect();
app.use(express.urlencoded({extended:false}))

app.post('/login',(req,res)=>{
    let {username,password} = req.body;
    let sql = `select username,password from user where username = '${username}' and password ='${password}'`
  con.query(sql,(err,results)=>{
    console.log(err,results);
    if(results.username='undefined'){
        res.send({code:500,msg:'用户名或密码错误'})
        return;
    }
    if(results.password='undefined'){
        res.send({code:500,msg:'用户名或密码错误'})
        return;
    }
    if(results.length>0){
        res.send({code:200,msg:'登录成功'})
    }
  })
});